﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Bricks.Component.Data
{
    /// <summary>
    /// 服务器SQL操作辅助类（可用于读取视图）
    /// </summary>
    /// <typeparam name="TEntity"></typeparam>
    public class DbSqlHelper<TEntity>
    {
        /// <summary>
        /// 执行SQL（可执行视图）
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <returns></returns>
        public static List<TEntity> SqlQueryCommon(string sql)
        {
            using (EFDbContext dbContext = new EFDbContext())
            {
                return dbContext.Database.SqlQuery<TEntity>(sql).ToList();
            }
        }
    }

    public class DbSqlHelper
    {
        /// <summary>
        /// 执行SQL（可执行视图）
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <returns></returns>
        public static int ExecuteSqlCommand(string sql)
        {
            using (EFDbContext dbContext = new EFDbContext())
            {
                return dbContext.Database.ExecuteSqlCommand(sql);
            }
        }
    }
}
